package com.atom.app.mvvm

import com.atom.app.mvvm.stack.AppRegisterCallback
import com.atom.app.mvvm.ui.activities.SplashActivity
import com.atom.module.logger.Logger
import com.atom.module.mvvm.base.AbstractApplication
import com.atom.module.mvvm.util.Auto
import com.atom.module.reporter.CrashReporter
import com.tencent.mmkv.MMKV

class App : AbstractApplication() {

    companion object {

        private lateinit var instance: App

        fun getApp(): App {
            return instance
        }
    }

    override fun onCreate() {
        super.onCreate()
        instance = this
        // Logger init
        Logger.init(this, isDebug = true)
        // CrashReport
        CrashReporter.initialize(this)
        CrashReporter.setRestartActivity(SplashActivity::class.java)
        CrashReporter.setReportHandler { error, callback ->
            Logger.e(error)
            callback.onCallback("Success")
        }
        // MMKV Init
        MMKV.initialize(this)
        // Auto Init
        if (BuildConfig.DEBUG) {
            Logger.e("debug")
            Auto.initAuto(this)
        }
        // 注册Stack
        this.registerActivityLifecycleCallbacks(AppRegisterCallback())
    }

}
